<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>positioning_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_positioning_positioning_test.js.html">positioning_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Unit tests for goog.position.
<a name="line17"></a> *
<a name="line18"></a> * @author eae@google.com (Emil A Eklund)
<a name="line19"></a> */
<a name="line20"></a>
<a name="line21"></a>
<a name="line22"></a>goog.provide(&#39;goog.positioningTest&#39;);
<a name="line23"></a>
<a name="line24"></a>goog.require(&#39;goog.dom&#39;);
<a name="line25"></a>goog.require(&#39;goog.math.Box&#39;);
<a name="line26"></a>goog.require(&#39;goog.math.Coordinate&#39;);
<a name="line27"></a>goog.require(&#39;goog.math.Rect&#39;);
<a name="line28"></a>goog.require(&#39;goog.positioning&#39;);
<a name="line29"></a>goog.require(&#39;goog.style&#39;);
<a name="line30"></a>goog.require(&#39;goog.testing.ExpectedFailures&#39;);
<a name="line31"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line32"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line33"></a>goog.require(&#39;goog.userAgent.product&#39;);
<a name="line34"></a>
<a name="line35"></a>goog.setTestOnly(&#39;goog.positioningTest&#39;);
<a name="line36"></a>
<a name="line37"></a>// Allow positions to be off by one in gecko as it reports scrolling
<a name="line38"></a>// offsets in steps of 2.
<a name="line39"></a>var ALLOWED_OFFSET = goog.userAgent.GECKO ? 1 : 0;
<a name="line40"></a>// Error bar for positions since some browsers are not super accurate
<a name="line41"></a>// in reporting them.
<a name="line42"></a>var EPSILON = 2;
<a name="line43"></a>
<a name="line44"></a>var expectedFailures = new goog.testing.ExpectedFailures();
<a name="line45"></a>
<a name="line46"></a>var corner = goog.positioning.Corner;
<a name="line47"></a>var overflow = goog.positioning.Overflow;
<a name="line48"></a>var testArea;
<a name="line49"></a>
<a name="line50"></a>function setUp() {
<a name="line51"></a>  window.scrollTo(0, 0);
<a name="line52"></a>
<a name="line53"></a>  var viewportSize = goog.dom.getViewportSize();
<a name="line54"></a>  // Some tests need enough size viewport.
<a name="line55"></a>  if (viewportSize.width &lt; 600 || viewportSize.height &lt; 600) {
<a name="line56"></a>    window.moveTo(0, 0);
<a name="line57"></a>    window.resizeTo(640, 640);
<a name="line58"></a>  }
<a name="line59"></a>
<a name="line60"></a>  testArea = goog.dom.getElement(&#39;test-area&#39;);
<a name="line61"></a>}
<a name="line62"></a>
<a name="line63"></a>function tearDown() {
<a name="line64"></a>  expectedFailures.handleTearDown();
<a name="line65"></a>  testArea.setAttribute(&#39;style&#39;, &#39;&#39;);
<a name="line66"></a>  testArea.innerHTML = &#39;&#39;;
<a name="line67"></a>}
<a name="line68"></a>
<a name="line69"></a>/**
<a name="line70"></a> * This is used to round pixel values on FF3 Mac.
<a name="line71"></a> */
<a name="line72"></a>function assertRoundedEquals(a, b, c) {
<a name="line73"></a>  function round(x) {
<a name="line74"></a>    return goog.userAgent.GECKO &amp;&amp; (goog.userAgent.MAC || goog.userAgent.X11) &amp;&amp;
<a name="line75"></a>        goog.userAgent.isVersion(&#39;1.9&#39;) ? Math.round(x) : x;
<a name="line76"></a>  }
<a name="line77"></a>  if (arguments.length == 3) {
<a name="line78"></a>    assertRoughlyEquals(a, round(b), round(c), ALLOWED_OFFSET);
<a name="line79"></a>  } else {
<a name="line80"></a>    assertRoughlyEquals(round(a), round(b), ALLOWED_OFFSET);
<a name="line81"></a>  }
<a name="line82"></a>}
<a name="line83"></a>
<a name="line84"></a>function testPositionAtAnchorLeftToRight() {
<a name="line85"></a>  var anchor = document.getElementById(&#39;anchor1&#39;);
<a name="line86"></a>  var popup = document.getElementById(&#39;popup1&#39;);
<a name="line87"></a>
<a name="line88"></a>  // Anchor top left to top left.
<a name="line89"></a>  goog.positioning.positionAtAnchor(anchor, corner.TOP_LEFT,
<a name="line90"></a>                                    popup, corner.TOP_LEFT);
<a name="line91"></a>  var anchorRect = goog.style.getBounds(anchor);
<a name="line92"></a>  var popupRect = goog.style.getBounds(popup);
<a name="line93"></a>  assertRoundedEquals(&#39;Left edge of popup should line up with left edge &#39; +
<a name="line94"></a>                      &#39;of anchor.&#39;,
<a name="line95"></a>                      anchorRect.left,
<a name="line96"></a>                      popupRect.left);
<a name="line97"></a>  assertRoundedEquals(&#39;Popup should have the same y position as the anchor.&#39;,
<a name="line98"></a>                      anchorRect.top,
<a name="line99"></a>                      popupRect.top);
<a name="line100"></a>
<a name="line101"></a>  // Anchor top left to bottom left.
<a name="line102"></a>  goog.positioning.positionAtAnchor(anchor, corner.BOTTOM_LEFT,
<a name="line103"></a>                                    popup, corner.TOP_LEFT);
<a name="line104"></a>  anchorRect = goog.style.getBounds(anchor);
<a name="line105"></a>  popupRect = goog.style.getBounds(popup);
<a name="line106"></a>  assertRoundedEquals(&#39;Left edge of popup should line up with left edge &#39; +
<a name="line107"></a>                      &#39;of anchor.&#39;,
<a name="line108"></a>                      anchorRect.left,
<a name="line109"></a>                      popupRect.left);
<a name="line110"></a>  assertRoundedEquals(&#39;Popup should be positioned just below the anchor.&#39;,
<a name="line111"></a>                      anchorRect.top + anchorRect.height,
<a name="line112"></a>                      popupRect.top);
<a name="line113"></a>
<a name="line114"></a>  // Anchor top left to top right.
<a name="line115"></a>  goog.positioning.positionAtAnchor(anchor, corner.TOP_RIGHT,
<a name="line116"></a>                                    popup, corner.TOP_LEFT);
<a name="line117"></a>  anchorRect = goog.style.getBounds(anchor);
<a name="line118"></a>  popupRect = goog.style.getBounds(popup);
<a name="line119"></a>  assertRoundedEquals(&#39;Popup should be positioned just right of the anchor.&#39;,
<a name="line120"></a>                      anchorRect.left + anchorRect.width,
<a name="line121"></a>                      popupRect.left);
<a name="line122"></a>  assertRoundedEquals(&#39;Popup should have the same y position as the anchor.&#39;,
<a name="line123"></a>                      anchorRect.top,
<a name="line124"></a>                      popupRect.top);
<a name="line125"></a>
<a name="line126"></a>  // Anchor top right to bottom right.
<a name="line127"></a>  goog.positioning.positionAtAnchor(anchor, corner.BOTTOM_RIGHT,
<a name="line128"></a>                                    popup, corner.TOP_RIGHT);
<a name="line129"></a>  anchorRect = goog.style.getBounds(anchor);
<a name="line130"></a>  popupRect = goog.style.getBounds(popup);
<a name="line131"></a>  assertRoundedEquals(&#39;Right edge of popup should line up with right edge &#39; +
<a name="line132"></a>                      &#39;of anchor.&#39;,
<a name="line133"></a>                      anchorRect.left + anchorRect.width,
<a name="line134"></a>                      popupRect.left + popupRect.width);
<a name="line135"></a>  assertRoundedEquals(&#39;Popup should be positioned just below the anchor.&#39;,
<a name="line136"></a>                      anchorRect.top + anchorRect.height,
<a name="line137"></a>                      popupRect.top);
<a name="line138"></a>
<a name="line139"></a>  // Anchor top start to bottom start.
<a name="line140"></a>  goog.positioning.positionAtAnchor(anchor, corner.BOTTOM_START,
<a name="line141"></a>                                    popup, corner.TOP_START);
<a name="line142"></a>  anchorRect = goog.style.getBounds(anchor);
<a name="line143"></a>  popupRect = goog.style.getBounds(popup);
<a name="line144"></a>  assertRoundedEquals(&#39;Left edge of popup should line up with left edge &#39; +
<a name="line145"></a>                      &#39;of anchor.&#39;,
<a name="line146"></a>                      anchorRect.left,
<a name="line147"></a>                      popupRect.left);
<a name="line148"></a>  assertRoundedEquals(&#39;Popup should be positioned just below the anchor.&#39;,
<a name="line149"></a>                      anchorRect.top + anchorRect.height,
<a name="line150"></a>                      popupRect.top);
<a name="line151"></a>}
<a name="line152"></a>
<a name="line153"></a>
<a name="line154"></a>function testPositionAtAnchorWithOffset() {
<a name="line155"></a>  var anchor = document.getElementById(&#39;anchor1&#39;);
<a name="line156"></a>  var popup = document.getElementById(&#39;popup1&#39;);
<a name="line157"></a>
<a name="line158"></a>  // Anchor top left to top left with an offset moving the popup away from the
<a name="line159"></a>  // anchor.
<a name="line160"></a>  goog.positioning.positionAtAnchor(anchor, corner.TOP_LEFT,
<a name="line161"></a>                                    popup, corner.TOP_LEFT,
<a name="line162"></a>                                    newCoord(-15, -20));
<a name="line163"></a>  var anchorRect = goog.style.getBounds(anchor);
<a name="line164"></a>  var popupRect = goog.style.getBounds(popup);
<a name="line165"></a>  assertRoundedEquals(&#39;Left edge of popup should be fifteen pixels from &#39; +
<a name="line166"></a>                      &#39;anchor.&#39;,
<a name="line167"></a>                      anchorRect.left,
<a name="line168"></a>                      popupRect.left + 15);
<a name="line169"></a>  assertRoundedEquals(&#39;Top edge of popup should be twenty pixels from anchor.&#39;,
<a name="line170"></a>                      anchorRect.top,
<a name="line171"></a>                      popupRect.top + 20);
<a name="line172"></a>
<a name="line173"></a>  // Anchor top left to top left with an offset moving the popup towards the
<a name="line174"></a>  // anchor.
<a name="line175"></a>  goog.positioning.positionAtAnchor(anchor, corner.TOP_LEFT,
<a name="line176"></a>                                    popup, corner.TOP_LEFT,
<a name="line177"></a>                                    newCoord(3, 1));
<a name="line178"></a>  anchorRect = goog.style.getBounds(anchor);
<a name="line179"></a>  popupRect = goog.style.getBounds(popup);
<a name="line180"></a>  assertRoundedEquals(&#39;Left edge of popup should be three pixels right of &#39; +
<a name="line181"></a>                      &#39;the anchor\&#39;s left edge&#39;,
<a name="line182"></a>                      anchorRect.left,
<a name="line183"></a>                      popupRect.left - 3);
<a name="line184"></a>  assertRoundedEquals(&#39;Top edge of popup should be one pixel below of the &#39; +
<a name="line185"></a>                      &#39;anchor\&#39;s top edge&#39;,
<a name="line186"></a>                      anchorRect.top,
<a name="line187"></a>                      popupRect.top - 1);
<a name="line188"></a>}
<a name="line189"></a>
<a name="line190"></a>
<a name="line191"></a>function testPositionAtAnchorOverflowLeftEdgeRightToLeft() {
<a name="line192"></a>  var anchor = document.getElementById(&#39;anchor5&#39;);
<a name="line193"></a>  var popup = document.getElementById(&#39;popup5&#39;);
<a name="line194"></a>
<a name="line195"></a>  var status = goog.positioning.positionAtAnchor(anchor, corner.TOP_LEFT,
<a name="line196"></a>                                                 popup, corner.TOP_RIGHT,
<a name="line197"></a>                                                 undefined, undefined,
<a name="line198"></a>                                                 overflow.FAIL_X);
<a name="line199"></a>  assertFalse(&#39;Positioning operation should have failed.&#39;,
<a name="line200"></a>              (status &amp; goog.positioning.OverflowStatus.FAILED) == 0);
<a name="line201"></a>
<a name="line202"></a>  // Change overflow strategy to ADJUST.
<a name="line203"></a>  status = goog.positioning.positionAtAnchor(anchor, corner.TOP_LEFT,
<a name="line204"></a>                                             popup, corner.TOP_RIGHT,
<a name="line205"></a>                                             undefined, undefined,
<a name="line206"></a>                                             overflow.ADJUST_X);
<a name="line207"></a>
<a name="line208"></a>  // Fails in Chrome because of infrastructure issues, temporarily disabled.
<a name="line209"></a>  // See b/4274723.
<a name="line210"></a>  expectedFailures.expectFailureFor(goog.userAgent.product.CHROME);
<a name="line211"></a>  try {
<a name="line212"></a>    assertTrue(&#39;Positioning operation should have been successful.&#39;,
<a name="line213"></a>               (status &amp; goog.positioning.OverflowStatus.FAILED) == 0);
<a name="line214"></a>    assertTrue(&#39;Positioning operation should have been adjusted.&#39;,
<a name="line215"></a>               (status &amp; goog.positioning.OverflowStatus.ADJUSTED_X) != 0);
<a name="line216"></a>  } catch (e) {
<a name="line217"></a>    expectedFailures.handleException(e);
<a name="line218"></a>  }
<a name="line219"></a>
<a name="line220"></a>  var anchorRect = goog.style.getBounds(anchor);
<a name="line221"></a>  var popupRect = goog.style.getBounds(popup);
<a name="line222"></a>  var parentRect = goog.style.getBounds(anchor.parentNode);
<a name="line223"></a>  assertTrue(&#39;Position should have been adjusted so that the left edge of &#39; +
<a name="line224"></a>             &#39;the popup is left of the anchor but still within the bounding &#39; +
<a name="line225"></a>             &#39;box of the parent container.&#39;,
<a name="line226"></a>      anchorRect.left &lt;= popupRect.left &lt;= parentRect.left);
<a name="line227"></a>
<a name="line228"></a>}
<a name="line229"></a>
<a name="line230"></a>
<a name="line231"></a>function testPositionAtAnchorWithMargin() {
<a name="line232"></a>  var anchor = document.getElementById(&#39;anchor1&#39;);
<a name="line233"></a>  var popup = document.getElementById(&#39;popup1&#39;);
<a name="line234"></a>
<a name="line235"></a>  // Anchor top left to top left.
<a name="line236"></a>  goog.positioning.positionAtAnchor(anchor, corner.TOP_LEFT,
<a name="line237"></a>                                    popup, corner.TOP_LEFT, undefined,
<a name="line238"></a>                                    new goog.math.Box(1, 2, 3, 4));
<a name="line239"></a>  var anchorRect = goog.style.getBounds(anchor);
<a name="line240"></a>  var popupRect = goog.style.getBounds(popup);
<a name="line241"></a>  assertRoundedEquals(&#39;Left edge of popup should be four pixels from anchor.&#39;,
<a name="line242"></a>                      anchorRect.left,
<a name="line243"></a>                      popupRect.left - 4);
<a name="line244"></a>  assertRoundedEquals(&#39;Top edge of popup should be one pixels from anchor.&#39;,
<a name="line245"></a>                      anchorRect.top,
<a name="line246"></a>                      popupRect.top - 1);
<a name="line247"></a>
<a name="line248"></a>  // Anchor top right to bottom right.
<a name="line249"></a>  goog.positioning.positionAtAnchor(anchor, corner.BOTTOM_RIGHT,
<a name="line250"></a>                                    popup, corner.TOP_RIGHT, undefined,
<a name="line251"></a>                                    new goog.math.Box(1, 2, 3, 4));
<a name="line252"></a>  anchorRect = goog.style.getBounds(anchor);
<a name="line253"></a>  popupRect = goog.style.getBounds(popup);
<a name="line254"></a>
<a name="line255"></a>  var visibleAnchorRect = goog.positioning.getVisiblePart_(anchor);
<a name="line256"></a>
<a name="line257"></a>  assertRoundedEquals(&#39;Right edge of popup should line up with right edge &#39; +
<a name="line258"></a>                      &#39;of anchor.&#39;,
<a name="line259"></a>                      visibleAnchorRect.left + visibleAnchorRect.width,
<a name="line260"></a>                      popupRect.left + popupRect.width + 2);
<a name="line261"></a>
<a name="line262"></a>  assertRoundedEquals(&#39;Popup should be positioned just below the anchor.&#39;,
<a name="line263"></a>                      visibleAnchorRect.top + visibleAnchorRect.height,
<a name="line264"></a>                      popupRect.top - 1);
<a name="line265"></a>
<a name="line266"></a>}
<a name="line267"></a>
<a name="line268"></a>
<a name="line269"></a>function testPositionAtAnchorRightToLeft() {
<a name="line270"></a>  if (goog.userAgent.IE &amp;&amp; goog.userAgent.isVersion(&#39;6&#39;)) {
<a name="line271"></a>    // These tests fails with IE6.
<a name="line272"></a>    // TODO(user): Investigate the reason.
<a name="line273"></a>    return;
<a name="line274"></a>  }
<a name="line275"></a>
<a name="line276"></a>  var anchor = document.getElementById(&#39;anchor2&#39;);
<a name="line277"></a>  var popup = document.getElementById(&#39;popup2&#39;);
<a name="line278"></a>
<a name="line279"></a>  // Anchor top left to top left.
<a name="line280"></a>  goog.positioning.positionAtAnchor(anchor, corner.TOP_LEFT,
<a name="line281"></a>                                    popup, corner.TOP_LEFT);
<a name="line282"></a>  var anchorRect = goog.style.getBounds(anchor);
<a name="line283"></a>  var popupRect = goog.style.getBounds(popup);
<a name="line284"></a>
<a name="line285"></a>  assertRoundedEquals(&#39;Left edge of popup should line up with left edge &#39; +
<a name="line286"></a>                      &#39;of anchor.&#39;,
<a name="line287"></a>                      anchorRect.left,
<a name="line288"></a>                      popupRect.left);
<a name="line289"></a>  assertRoundedEquals(&#39;Popup should have the same y position as the anchor.&#39;,
<a name="line290"></a>                      anchorRect.top,
<a name="line291"></a>                      popupRect.top);
<a name="line292"></a>
<a name="line293"></a>  // Anchor top start to bottom start.
<a name="line294"></a>  goog.positioning.positionAtAnchor(anchor, corner.BOTTOM_START,
<a name="line295"></a>                                    popup, corner.TOP_START);
<a name="line296"></a>  anchorRect = goog.style.getBounds(anchor);
<a name="line297"></a>  popupRect = goog.style.getBounds(popup);
<a name="line298"></a>  assertRoundedEquals(&#39;Right edge of popup should line up with right edge &#39; +
<a name="line299"></a>                      &#39;of anchor.&#39;,
<a name="line300"></a>                      anchorRect.left + anchorRect.width,
<a name="line301"></a>                      popupRect.left + popupRect.width);
<a name="line302"></a>  assertRoundedEquals(&#39;Popup should be positioned just below the anchor.&#39;,
<a name="line303"></a>                      anchorRect.top + anchorRect.height,
<a name="line304"></a>                      popupRect.top);
<a name="line305"></a>}
<a name="line306"></a>
<a name="line307"></a>function testPositionAtAnchorRightToLeftWithScroll() {
<a name="line308"></a>  if (goog.userAgent.IE &amp;&amp; goog.userAgent.isVersion(&#39;6&#39;)) {
<a name="line309"></a>    // These tests fails with IE6.
<a name="line310"></a>    // TODO(user): Investigate the reason.
<a name="line311"></a>    return;
<a name="line312"></a>  }
<a name="line313"></a>
<a name="line314"></a>  var anchor = document.getElementById(&#39;anchor8&#39;);
<a name="line315"></a>  var popup = document.getElementById(&#39;popup8&#39;);
<a name="line316"></a>
<a name="line317"></a>  // Anchor top left to top left.
<a name="line318"></a>  goog.positioning.positionAtAnchor(anchor, corner.TOP_LEFT,
<a name="line319"></a>                                    popup, corner.TOP_LEFT);
<a name="line320"></a>  var anchorRect = goog.style.getBounds(anchor);
<a name="line321"></a>  var popupRect = goog.style.getBounds(popup);
<a name="line322"></a>
<a name="line323"></a>  assertRoundedEquals(&#39;Left edge of popup should line up with left edge &#39; +
<a name="line324"></a>                      &#39;of anchor.&#39;,
<a name="line325"></a>                      anchorRect.left,
<a name="line326"></a>                      popupRect.left);
<a name="line327"></a>  assertRoundedEquals(&#39;Popup should have the same y position as the anchor.&#39;,
<a name="line328"></a>                      anchorRect.top,
<a name="line329"></a>                      popupRect.top);
<a name="line330"></a>
<a name="line331"></a>  // Anchor top start to bottom start.
<a name="line332"></a>  goog.positioning.positionAtAnchor(anchor, corner.BOTTOM_START,
<a name="line333"></a>                                    popup, corner.TOP_START);
<a name="line334"></a>  anchorRect = goog.style.getBounds(anchor);
<a name="line335"></a>  popupRect = goog.style.getBounds(popup);
<a name="line336"></a>
<a name="line337"></a>  var visibleAnchorRect = goog.positioning.getVisiblePart_(anchor);
<a name="line338"></a>  var visibleAnchorBox = visibleAnchorRect.toBox();
<a name="line339"></a>
<a name="line340"></a>  assertRoundedEquals(&#39;Right edge of popup should line up with right edge &#39; +
<a name="line341"></a>                      &#39;of anchor.&#39;,
<a name="line342"></a>                      anchorRect.left + anchorRect.width,
<a name="line343"></a>                      popupRect.left + popupRect.width);
<a name="line344"></a>  assertRoundedEquals(&#39;Popup should be positioned just below the anchor.&#39;,
<a name="line345"></a>                      visibleAnchorBox.bottom,
<a name="line346"></a>                      popupRect.top);
<a name="line347"></a>}
<a name="line348"></a>
<a name="line349"></a>function testPositionAtAnchorBodyViewport() {
<a name="line350"></a>  var anchor = document.getElementById(&#39;anchor1&#39;);
<a name="line351"></a>  var popup = document.getElementById(&#39;popup3&#39;);
<a name="line352"></a>
<a name="line353"></a>  // Anchor top left to top left.
<a name="line354"></a>  goog.positioning.positionAtAnchor(anchor, corner.TOP_LEFT,
<a name="line355"></a>                                    popup, corner.TOP_LEFT);
<a name="line356"></a>  var anchorRect = goog.style.getBounds(anchor);
<a name="line357"></a>  var popupRect = goog.style.getBounds(popup);
<a name="line358"></a>  assertEquals(&#39;Left edge of popup should line up with left edge of anchor.&#39;,
<a name="line359"></a>               anchorRect.left,
<a name="line360"></a>               popupRect.left);
<a name="line361"></a>  assertEquals(&#39;Popup should have the same y position as the anchor.&#39;,
<a name="line362"></a>               anchorRect.top,
<a name="line363"></a>               popupRect.top);
<a name="line364"></a>
<a name="line365"></a>  // Anchor top start to bottom right.
<a name="line366"></a>  goog.positioning.positionAtAnchor(anchor, corner.BOTTOM_RIGHT,
<a name="line367"></a>                                    popup, corner.TOP_RIGHT);
<a name="line368"></a>  anchorRect = goog.style.getBounds(anchor);
<a name="line369"></a>  popupRect = goog.style.getBounds(popup);
<a name="line370"></a>  assertEquals(&#39;Right edge of popup should line up with right edge of anchor.&#39;,
<a name="line371"></a>               anchorRect.left + anchorRect.width,
<a name="line372"></a>               popupRect.left + popupRect.width);
<a name="line373"></a>  assertEquals(&#39;Popup should be positioned just below the anchor.&#39;,
<a name="line374"></a>               anchorRect.top + anchorRect.height,
<a name="line375"></a>               popupRect.top);
<a name="line376"></a>
<a name="line377"></a>  // Anchor top right to top left.
<a name="line378"></a>  goog.positioning.positionAtAnchor(anchor, corner.TOP_LEFT,
<a name="line379"></a>                                    popup, corner.TOP_RIGHT);
<a name="line380"></a>  anchorRect = goog.style.getBounds(anchor);
<a name="line381"></a>  popupRect = goog.style.getBounds(popup);
<a name="line382"></a>  assertEquals(&#39;Right edge of popup should line up with left edge of anchor.&#39;,
<a name="line383"></a>               anchorRect.left,
<a name="line384"></a>               popupRect.left + popupRect.width);
<a name="line385"></a>  assertEquals(&#39;Popup should have the same y position as the anchor.&#39;,
<a name="line386"></a>               anchorRect.top,
<a name="line387"></a>               popupRect.top);
<a name="line388"></a>}
<a name="line389"></a>
<a name="line390"></a>function testPositionAtAnchorSpecificViewport() {
<a name="line391"></a>  var anchor = document.getElementById(&#39;anchor1&#39;);
<a name="line392"></a>  var popup = document.getElementById(&#39;popup3&#39;);
<a name="line393"></a>
<a name="line394"></a>  // Anchor top right to top left within outerbox.
<a name="line395"></a>  var status = goog.positioning.positionAtAnchor(anchor, corner.TOP_LEFT,
<a name="line396"></a>                                                 popup, corner.TOP_RIGHT,
<a name="line397"></a>                                                 undefined, undefined,
<a name="line398"></a>                                                 overflow.FAIL_X);
<a name="line399"></a>  anchorRect = goog.style.getBounds(anchor);
<a name="line400"></a>  popupRect = goog.style.getBounds(popup);
<a name="line401"></a>  assertTrue(&#39;Positioning operation should have been successful.&#39;,
<a name="line402"></a>             (status &amp; goog.positioning.OverflowStatus.FAILED) == 0);
<a name="line403"></a>  assertTrue(&#39;X position should not have been adjusted.&#39;,
<a name="line404"></a>             (status &amp; goog.positioning.OverflowStatus.ADJUSTED_X) == 0);
<a name="line405"></a>  assertTrue(&#39;Y position should not have been adjusted.&#39;,
<a name="line406"></a>             (status &amp; goog.positioning.OverflowStatus.ADJUSTED_Y) == 0);
<a name="line407"></a>  assertEquals(&#39;Right edge of popup should line up with left edge of anchor.&#39;,
<a name="line408"></a>               anchorRect.left,
<a name="line409"></a>               popupRect.left + popupRect.width);
<a name="line410"></a>  assertEquals(&#39;Popup should have the same y position as the anchor.&#39;,
<a name="line411"></a>               anchorRect.top,
<a name="line412"></a>               popupRect.top);
<a name="line413"></a>
<a name="line414"></a>  // position again within box1.
<a name="line415"></a>  var box = document.getElementById(&#39;box1&#39;);
<a name="line416"></a>  var viewport = goog.style.getBounds(box);
<a name="line417"></a>  status = goog.positioning.positionAtAnchor(anchor, corner.TOP_LEFT,
<a name="line418"></a>                                             popup, corner.TOP_RIGHT,
<a name="line419"></a>                                             undefined, undefined,
<a name="line420"></a>                                             overflow.FAIL_X, undefined,
<a name="line421"></a>                                             viewport);
<a name="line422"></a>  assertFalse(&#39;Positioning operation should have failed.&#39;,
<a name="line423"></a>              (status &amp; goog.positioning.OverflowStatus.FAILED) == 0);
<a name="line424"></a>
<a name="line425"></a>  // Change overflow strategy to adjust.
<a name="line426"></a>  status = goog.positioning.positionAtAnchor(anchor, corner.TOP_LEFT,
<a name="line427"></a>                                             popup, corner.TOP_RIGHT,
<a name="line428"></a>                                             undefined, undefined,
<a name="line429"></a>                                             overflow.ADJUST_X, undefined,
<a name="line430"></a>                                             viewport);
<a name="line431"></a>  anchorRect = goog.style.getBounds(anchor);
<a name="line432"></a>  popupRect = goog.style.getBounds(popup);
<a name="line433"></a>  assertTrue(&#39;Positioning operation should have been successful.&#39;,
<a name="line434"></a>             (status &amp; goog.positioning.OverflowStatus.FAILED) == 0);
<a name="line435"></a>  assertFalse(&#39;X position should have been adjusted.&#39;,
<a name="line436"></a>              (status &amp; goog.positioning.OverflowStatus.ADJUSTED_X) == 0);
<a name="line437"></a>  assertTrue(&#39;Y position should not have been adjusted.&#39;,
<a name="line438"></a>             (status &amp; goog.positioning.OverflowStatus.ADJUSTED_Y) == 0);
<a name="line439"></a>  assertRoughlyEquals(
<a name="line440"></a>      &#39;Left edge of popup should line up with left edge of viewport.&#39;,
<a name="line441"></a>      viewport.left, popupRect.left, EPSILON);
<a name="line442"></a>  assertEquals(&#39;Popup should have the same y position as the anchor.&#39;,
<a name="line443"></a>               anchorRect.top,
<a name="line444"></a>               popupRect.top);
<a name="line445"></a>}
<a name="line446"></a>
<a name="line447"></a>function testPositionAtAnchorOutsideViewport() {
<a name="line448"></a>  var anchor = document.getElementById(&#39;anchor4&#39;);
<a name="line449"></a>  var popup = document.getElementById(&#39;popup1&#39;);
<a name="line450"></a>
<a name="line451"></a>  var status = goog.positioning.positionAtAnchor(anchor, corner.TOP_LEFT,
<a name="line452"></a>                                                 popup, corner.TOP_RIGHT);
<a name="line453"></a>  var anchorRect = goog.style.getBounds(anchor);
<a name="line454"></a>  var popupRect = goog.style.getBounds(popup);
<a name="line455"></a>  assertTrue(&#39;Positioning operation should have been successful.&#39;,
<a name="line456"></a>             (status &amp; goog.positioning.OverflowStatus.FAILED) == 0);
<a name="line457"></a>  assertTrue(&#39;X position should not have been adjusted.&#39;,
<a name="line458"></a>             (status &amp; goog.positioning.OverflowStatus.ADJUSTED_X) == 0);
<a name="line459"></a>  assertTrue(&#39;Y position should not have been adjusted.&#39;,
<a name="line460"></a>             (status &amp; goog.positioning.OverflowStatus.ADJUSTED_Y) == 0);
<a name="line461"></a>
<a name="line462"></a>  assertEquals(&#39;Right edge of popup should line up with left edge of anchor.&#39;,
<a name="line463"></a>               anchorRect.left,
<a name="line464"></a>               popupRect.left + popupRect.width);
<a name="line465"></a>
<a name="line466"></a>  // Change overflow strategy to fail.
<a name="line467"></a>  status = goog.positioning.positionAtAnchor(anchor, corner.BOTTOM_RIGHT,
<a name="line468"></a>                                             popup, corner.TOP_RIGHT,
<a name="line469"></a>                                             undefined, undefined,
<a name="line470"></a>                                             overflow.FAIL_X);
<a name="line471"></a>  assertFalse(&#39;Positioning operation should have failed.&#39;,
<a name="line472"></a>              (status &amp; goog.positioning.OverflowStatus.FAILED) == 0);
<a name="line473"></a>
<a name="line474"></a>  // Change overflow strategy to adjust.
<a name="line475"></a>  status = goog.positioning.positionAtAnchor(anchor, corner.BOTTOM_RIGHT,
<a name="line476"></a>                                             popup, corner.TOP_RIGHT,
<a name="line477"></a>                                             undefined, undefined,
<a name="line478"></a>                                             overflow.ADJUST_X);
<a name="line479"></a>  anchorRect = goog.style.getBounds(anchor);
<a name="line480"></a>  popupRect = goog.style.getBounds(popup);
<a name="line481"></a>  assertTrue(&#39;Positioning operation should have been successful.&#39;,
<a name="line482"></a>             (status &amp; goog.positioning.OverflowStatus.FAILED) == 0);
<a name="line483"></a>  assertFalse(&#39;X position should have been adjusted.&#39;,
<a name="line484"></a>              (status &amp; goog.positioning.OverflowStatus.ADJUSTED_X) == 0);
<a name="line485"></a>  assertTrue(&#39;Y position should not have been adjusted.&#39;,
<a name="line486"></a>             (status &amp; goog.positioning.OverflowStatus.ADJUSTED_Y) == 0);
<a name="line487"></a>  assertRoughlyEquals(
<a name="line488"></a>      &#39;Left edge of popup should line up with left edge of viewport.&#39;,
<a name="line489"></a>      0, popupRect.left, EPSILON);
<a name="line490"></a>  assertEquals(&#39;Popup should be positioned just below the anchor.&#39;,
<a name="line491"></a>               anchorRect.top + anchorRect.height,
<a name="line492"></a>               popupRect.top);
<a name="line493"></a>}
<a name="line494"></a>
<a name="line495"></a>
<a name="line496"></a>function testAdjustForViewportFailIgnore() {
<a name="line497"></a>  var f = goog.positioning.adjustForViewport_;
<a name="line498"></a>  var viewport = new goog.math.Box(100, 200, 200, 100);
<a name="line499"></a>  var overflow = goog.positioning.Overflow.IGNORE;
<a name="line500"></a>
<a name="line501"></a>  var pos = newCoord(150, 150);
<a name="line502"></a>  var size = newSize(50, 50);
<a name="line503"></a>  assertEquals(&#39;Viewport overflow should be ignored.&#39;,
<a name="line504"></a>               goog.positioning.OverflowStatus.NONE,
<a name="line505"></a>               f(pos, size, viewport, overflow));
<a name="line506"></a>
<a name="line507"></a>  pos = newCoord(150, 150);
<a name="line508"></a>  size = newSize(100, 50);
<a name="line509"></a>  assertEquals(&#39;Viewport overflow should be ignored.&#39;,
<a name="line510"></a>               goog.positioning.OverflowStatus.NONE,
<a name="line511"></a>               f(pos, size, viewport, overflow));
<a name="line512"></a>
<a name="line513"></a>  pos = newCoord(50, 50);
<a name="line514"></a>  size = newSize(50, 50);
<a name="line515"></a>  assertEquals(&#39;Viewport overflow should be ignored.&#39;,
<a name="line516"></a>               goog.positioning.OverflowStatus.NONE,
<a name="line517"></a>               f(pos, size, viewport, overflow));
<a name="line518"></a>}
<a name="line519"></a>
<a name="line520"></a>
<a name="line521"></a>function testAdjustForViewportFailXY() {
<a name="line522"></a>  var f = goog.positioning.adjustForViewport_;
<a name="line523"></a>  var viewport = new goog.math.Box(100, 200, 200, 100);
<a name="line524"></a>  var overflow = goog.positioning.Overflow.FAIL_X |
<a name="line525"></a>                 goog.positioning.Overflow.FAIL_Y;
<a name="line526"></a>
<a name="line527"></a>  var pos = newCoord(150, 150);
<a name="line528"></a>  var size = newSize(50, 50);
<a name="line529"></a>  assertEquals(&#39;Element should not overflow viewport.&#39;,
<a name="line530"></a>               goog.positioning.OverflowStatus.NONE,
<a name="line531"></a>               f(pos, size, viewport, overflow));
<a name="line532"></a>
<a name="line533"></a>  pos = newCoord(150, 150);
<a name="line534"></a>  size = newSize(100, 50);
<a name="line535"></a>  assertEquals(&#39;Element should overflow the right edge of viewport.&#39;,
<a name="line536"></a>               goog.positioning.OverflowStatus.FAILED_RIGHT,
<a name="line537"></a>               f(pos, size, viewport, overflow));
<a name="line538"></a>
<a name="line539"></a>  pos = newCoord(150, 150);
<a name="line540"></a>  size = newSize(50, 100);
<a name="line541"></a>  assertEquals(&#39;Element should overflow the bottom edge of viewport.&#39;,
<a name="line542"></a>               goog.positioning.OverflowStatus.FAILED_BOTTOM,
<a name="line543"></a>               f(pos, size, viewport, overflow));
<a name="line544"></a>
<a name="line545"></a>  pos = newCoord(50, 150);
<a name="line546"></a>  size = newSize(50, 50);
<a name="line547"></a>  assertEquals(&#39;Element should overflow the left edge of viewport.&#39;,
<a name="line548"></a>               goog.positioning.OverflowStatus.FAILED_LEFT,
<a name="line549"></a>               f(pos, size, viewport, overflow));
<a name="line550"></a>
<a name="line551"></a>  pos = newCoord(150, 50);
<a name="line552"></a>  size = newSize(50, 50);
<a name="line553"></a>  assertEquals(&#39;Element should overflow the top edge of viewport.&#39;,
<a name="line554"></a>               goog.positioning.OverflowStatus.FAILED_TOP,
<a name="line555"></a>               f(pos, size, viewport, overflow));
<a name="line556"></a>
<a name="line557"></a>  pos = newCoord(50, 50);
<a name="line558"></a>  size = newSize(50, 50);
<a name="line559"></a>  assertEquals(&#39;Element should overflow the left &amp; top edges of viewport.&#39;,
<a name="line560"></a>               goog.positioning.OverflowStatus.FAILED_LEFT |
<a name="line561"></a>               goog.positioning.OverflowStatus.FAILED_TOP,
<a name="line562"></a>               f(pos, size, viewport, overflow));
<a name="line563"></a>}
<a name="line564"></a>
<a name="line565"></a>
<a name="line566"></a>function testAdjustForViewportAdjustXFailY() {
<a name="line567"></a>  var f = goog.positioning.adjustForViewport_;
<a name="line568"></a>  var viewport = new goog.math.Box(100, 200, 200, 100);
<a name="line569"></a>  var overflow = goog.positioning.Overflow.ADJUST_X |
<a name="line570"></a>                 goog.positioning.Overflow.FAIL_Y;
<a name="line571"></a>
<a name="line572"></a>  var pos = newCoord(150, 150);
<a name="line573"></a>  var size = newSize(50, 50);
<a name="line574"></a>  assertEquals(&#39;Element should not overflow viewport.&#39;,
<a name="line575"></a>               goog.positioning.OverflowStatus.NONE,
<a name="line576"></a>               f(pos, size, viewport, overflow));
<a name="line577"></a>  assertEquals(&#39;X Position should not have been changed.&#39;, 150, pos.x);
<a name="line578"></a>  assertEquals(&#39;Y Position should not have been changed.&#39;, 150, pos.y);
<a name="line579"></a>
<a name="line580"></a>  pos = newCoord(150, 150);
<a name="line581"></a>  size = newSize(100, 50);
<a name="line582"></a>  assertEquals(&#39;Element position should be adjusted not to overflow right &#39; +
<a name="line583"></a>               &#39;edge of viewport.&#39;,
<a name="line584"></a>               goog.positioning.OverflowStatus.ADJUSTED_X,
<a name="line585"></a>               f(pos, size, viewport, overflow));
<a name="line586"></a>  assertEquals(&#39;X Position should be adjusted to 100.&#39;, 100, pos.x);
<a name="line587"></a>  assertEquals(&#39;Y Position should not have been changed.&#39;, 150, pos.y);
<a name="line588"></a>
<a name="line589"></a>  pos = newCoord(50, 150);
<a name="line590"></a>  size = newSize(100, 50);
<a name="line591"></a>  assertEquals(&#39;Element position should be adjusted not to overflow left &#39; +
<a name="line592"></a>               &#39;edge of viewport.&#39;,
<a name="line593"></a>               goog.positioning.OverflowStatus.ADJUSTED_X,
<a name="line594"></a>               f(pos, size, viewport, overflow));
<a name="line595"></a>  assertEquals(&#39;X Position should be adjusted to 100.&#39;, 100, pos.x);
<a name="line596"></a>  assertEquals(&#39;Y Position should not have been changed.&#39;, 150, pos.y);
<a name="line597"></a>
<a name="line598"></a>
<a name="line599"></a>  pos = newCoord(50, 50);
<a name="line600"></a>  size = newSize(100, 50);
<a name="line601"></a>  assertEquals(&#39;Element position should be adjusted not to overflow left &#39; +
<a name="line602"></a>               &#39;edge of viewport, should overflow bottom edge.&#39;,
<a name="line603"></a>               goog.positioning.OverflowStatus.ADJUSTED_X |
<a name="line604"></a>               goog.positioning.OverflowStatus.FAILED_TOP,
<a name="line605"></a>               f(pos, size, viewport, overflow));
<a name="line606"></a>  assertEquals(&#39;X Position should be adjusted to 100.&#39;, 100, pos.x);
<a name="line607"></a>  assertEquals(&#39;Y Position should not have been changed.&#39;, 50, pos.y);
<a name="line608"></a>}
<a name="line609"></a>
<a name="line610"></a>
<a name="line611"></a>function testAdjustForViewportResizeHeight() {
<a name="line612"></a>  var f = goog.positioning.adjustForViewport_;
<a name="line613"></a>  var viewport = new goog.math.Box(0, 200, 200, 0);
<a name="line614"></a>  var overflow = goog.positioning.Overflow.RESIZE_HEIGHT;
<a name="line615"></a>
<a name="line616"></a>  var pos = newCoord(150, 150);
<a name="line617"></a>  var size = newSize(25, 100);
<a name="line618"></a>  assertEquals(&#39;Viewport height should be resized.&#39;,
<a name="line619"></a>               goog.positioning.OverflowStatus.HEIGHT_ADJUSTED,
<a name="line620"></a>               f(pos, size, viewport, overflow));
<a name="line621"></a>  assertEquals(&#39;Height should be resized to 50.&#39;,
<a name="line622"></a>               50, size.height);
<a name="line623"></a>
<a name="line624"></a>  var pos = newCoord(0, 0);
<a name="line625"></a>  var size = newSize(50, 250);
<a name="line626"></a>  assertEquals(&#39;Viewport height should be resized.&#39;,
<a name="line627"></a>               goog.positioning.OverflowStatus.HEIGHT_ADJUSTED,
<a name="line628"></a>               f(pos, size, viewport, overflow));
<a name="line629"></a>  assertEquals(&#39;Height should be resized to 200.&#39;,
<a name="line630"></a>               200, size.height);
<a name="line631"></a>
<a name="line632"></a>  var pos = newCoord(0, -50);
<a name="line633"></a>  var size = newSize(50, 240);
<a name="line634"></a>  assertEquals(&#39;Viewport height should be resized.&#39;,
<a name="line635"></a>               goog.positioning.OverflowStatus.HEIGHT_ADJUSTED,
<a name="line636"></a>               f(pos, size, viewport, overflow));
<a name="line637"></a>  assertEquals(&#39;Height should be resized to 190.&#39;,
<a name="line638"></a>               190, size.height);
<a name="line639"></a>
<a name="line640"></a>  pos = newCoord(150, 150);
<a name="line641"></a>  size = newSize(50, 50);
<a name="line642"></a>  assertEquals(&#39;No Viewport overflow.&#39;,
<a name="line643"></a>               goog.positioning.OverflowStatus.NONE,
<a name="line644"></a>               f(pos, size, viewport, overflow));
<a name="line645"></a>}
<a name="line646"></a>
<a name="line647"></a>
<a name="line648"></a>function testPositionAtCoordinateResizeHeight() {
<a name="line649"></a>  var f = goog.positioning.positionAtCoordinate;
<a name="line650"></a>  var viewport = new goog.math.Box(0, 50, 50, 0);
<a name="line651"></a>  var overflow = goog.positioning.Overflow.RESIZE_HEIGHT |
<a name="line652"></a>      goog.positioning.Overflow.ADJUST_Y;
<a name="line653"></a>  var popup = document.getElementById(&#39;popup1&#39;);
<a name="line654"></a>  var corner = goog.positioning.Corner.BOTTOM_LEFT;
<a name="line655"></a>
<a name="line656"></a>  var pos = newCoord(100, 100);
<a name="line657"></a>
<a name="line658"></a>  assertEquals(&#39;Viewport height should be resized.&#39;,
<a name="line659"></a>               goog.positioning.OverflowStatus.HEIGHT_ADJUSTED |
<a name="line660"></a>               goog.positioning.OverflowStatus.ADJUSTED_Y,
<a name="line661"></a>               f(pos, popup, corner, undefined, viewport, overflow));
<a name="line662"></a>  var bounds = goog.style.getSize(popup);
<a name="line663"></a>  assertEquals(&#39;Height should be resized to the size of the viewport.&#39;,
<a name="line664"></a>               50, bounds.height);
<a name="line665"></a>}
<a name="line666"></a>
<a name="line667"></a>
<a name="line668"></a>function testGetEffectiveCornerLeftToRight() {
<a name="line669"></a>  var f = goog.positioning.getEffectiveCorner;
<a name="line670"></a>  var el = document.getElementById(&#39;ltr&#39;);
<a name="line671"></a>
<a name="line672"></a>  assertEquals(&#39;TOP_LEFT should be unchanged for ltr.&#39;,
<a name="line673"></a>               corner.TOP_LEFT,
<a name="line674"></a>               f(el, corner.TOP_LEFT));
<a name="line675"></a>  assertEquals(&#39;TOP_RIGHT should be unchanged for ltr.&#39;,
<a name="line676"></a>               corner.TOP_RIGHT,
<a name="line677"></a>               f(el, corner.TOP_RIGHT));
<a name="line678"></a>  assertEquals(&#39;BOTTOM_LEFT should be unchanged for ltr.&#39;,
<a name="line679"></a>               corner.BOTTOM_LEFT,
<a name="line680"></a>               f(el, corner.BOTTOM_LEFT));
<a name="line681"></a>  assertEquals(&#39;BOTTOM_RIGHT should be unchanged for ltr.&#39;,
<a name="line682"></a>               corner.BOTTOM_RIGHT,
<a name="line683"></a>               f(el, corner.BOTTOM_RIGHT));
<a name="line684"></a>
<a name="line685"></a>  assertEquals(&#39;TOP_START should be TOP_LEFT for ltr.&#39;,
<a name="line686"></a>               corner.TOP_LEFT,
<a name="line687"></a>               f(el, corner.TOP_START));
<a name="line688"></a>  assertEquals(&#39;TOP_END should be TOP_RIGHT for ltr.&#39;,
<a name="line689"></a>               corner.TOP_RIGHT,
<a name="line690"></a>               f(el, corner.TOP_END));
<a name="line691"></a>  assertEquals(&#39;BOTTOM_START should be BOTTOM_LEFT for ltr.&#39;,
<a name="line692"></a>               corner.BOTTOM_LEFT,
<a name="line693"></a>               f(el, corner.BOTTOM_START));
<a name="line694"></a>  assertEquals(&#39;BOTTOM_END should be BOTTOM_RIGHT for ltr.&#39;,
<a name="line695"></a>               corner.BOTTOM_RIGHT,
<a name="line696"></a>               f(el, corner.BOTTOM_END));
<a name="line697"></a>}
<a name="line698"></a>
<a name="line699"></a>
<a name="line700"></a>function testGetEffectiveCornerRightToLeft() {
<a name="line701"></a>  var f = goog.positioning.getEffectiveCorner;
<a name="line702"></a>  var el = document.getElementById(&#39;rtl&#39;);
<a name="line703"></a>
<a name="line704"></a>  assertEquals(&#39;TOP_LEFT should be unchanged for rtl.&#39;,
<a name="line705"></a>               corner.TOP_LEFT,
<a name="line706"></a>               f(el, corner.TOP_LEFT));
<a name="line707"></a>  assertEquals(&#39;TOP_RIGHT should be unchanged for rtl.&#39;,
<a name="line708"></a>               corner.TOP_RIGHT,
<a name="line709"></a>               f(el, corner.TOP_RIGHT));
<a name="line710"></a>  assertEquals(&#39;BOTTOM_LEFT should be unchanged for rtl.&#39;,
<a name="line711"></a>               corner.BOTTOM_LEFT,
<a name="line712"></a>               f(el, corner.BOTTOM_LEFT));
<a name="line713"></a>  assertEquals(&#39;BOTTOM_RIGHT should be unchanged for rtl.&#39;,
<a name="line714"></a>               corner.BOTTOM_RIGHT,
<a name="line715"></a>               f(el, corner.BOTTOM_RIGHT));
<a name="line716"></a>
<a name="line717"></a>  assertEquals(&#39;TOP_START should be TOP_RIGHT for rtl.&#39;,
<a name="line718"></a>               corner.TOP_RIGHT,
<a name="line719"></a>               f(el, corner.TOP_START));
<a name="line720"></a>  assertEquals(&#39;TOP_END should be TOP_LEFT for rtl.&#39;,
<a name="line721"></a>               corner.TOP_LEFT,
<a name="line722"></a>               f(el, corner.TOP_END));
<a name="line723"></a>  assertEquals(&#39;BOTTOM_START should be BOTTOM_RIGHT for rtl.&#39;,
<a name="line724"></a>               corner.BOTTOM_RIGHT,
<a name="line725"></a>               f(el, corner.BOTTOM_START));
<a name="line726"></a>  assertEquals(&#39;BOTTOM_END should be BOTTOM_LEFT for rtl.&#39;,
<a name="line727"></a>               corner.BOTTOM_LEFT,
<a name="line728"></a>               f(el, corner.BOTTOM_END));
<a name="line729"></a>}
<a name="line730"></a>
<a name="line731"></a>
<a name="line732"></a>function testFlipCornerHorizontal() {
<a name="line733"></a>  var f = goog.positioning.flipCornerHorizontal;
<a name="line734"></a>
<a name="line735"></a>  assertEquals(&#39;TOP_LEFT should be flipped to TOP_RIGHT.&#39;,
<a name="line736"></a>               corner.TOP_RIGHT,
<a name="line737"></a>               f(corner.TOP_LEFT));
<a name="line738"></a>  assertEquals(&#39;TOP_RIGHT should be flipped to TOP_LEFT.&#39;,
<a name="line739"></a>               corner.TOP_LEFT,
<a name="line740"></a>               f(corner.TOP_RIGHT));
<a name="line741"></a>  assertEquals(&#39;BOTTOM_LEFT should be flipped to BOTTOM_RIGHT.&#39;,
<a name="line742"></a>               corner.BOTTOM_RIGHT,
<a name="line743"></a>               f(corner.BOTTOM_LEFT));
<a name="line744"></a>  assertEquals(&#39;BOTTOM_RIGHT should be flipped to BOTTOM_LEFT.&#39;,
<a name="line745"></a>               corner.BOTTOM_LEFT,
<a name="line746"></a>               f(corner.BOTTOM_RIGHT));
<a name="line747"></a>
<a name="line748"></a>  assertEquals(&#39;TOP_START should be flipped to TOP_END.&#39;,
<a name="line749"></a>               corner.TOP_END,
<a name="line750"></a>               f(corner.TOP_START));
<a name="line751"></a>  assertEquals(&#39;TOP_END should be flipped to TOP_START.&#39;,
<a name="line752"></a>               corner.TOP_START,
<a name="line753"></a>               f(corner.TOP_END));
<a name="line754"></a>  assertEquals(&#39;BOTTOM_START should be flipped to BOTTOM_END.&#39;,
<a name="line755"></a>               corner.BOTTOM_END,
<a name="line756"></a>               f(corner.BOTTOM_START));
<a name="line757"></a>  assertEquals(&#39;BOTTOM_END should be flipped to BOTTOM_START.&#39;,
<a name="line758"></a>               corner.BOTTOM_START,
<a name="line759"></a>               f(corner.BOTTOM_END));
<a name="line760"></a>}
<a name="line761"></a>
<a name="line762"></a>
<a name="line763"></a>function testFlipCornerVertical() {
<a name="line764"></a>  var f = goog.positioning.flipCornerVertical;
<a name="line765"></a>
<a name="line766"></a>  assertEquals(&#39;TOP_LEFT should be flipped to BOTTOM_LEFT.&#39;,
<a name="line767"></a>               corner.BOTTOM_LEFT,
<a name="line768"></a>               f(corner.TOP_LEFT));
<a name="line769"></a>  assertEquals(&#39;TOP_RIGHT should be flipped to BOTTOM_RIGHT.&#39;,
<a name="line770"></a>               corner.BOTTOM_RIGHT,
<a name="line771"></a>               f(corner.TOP_RIGHT));
<a name="line772"></a>  assertEquals(&#39;BOTTOM_LEFT should be flipped to TOP_LEFT.&#39;,
<a name="line773"></a>               corner.TOP_LEFT,
<a name="line774"></a>               f(corner.BOTTOM_LEFT));
<a name="line775"></a>  assertEquals(&#39;BOTTOM_RIGHT should be flipped to TOP_RIGHT.&#39;,
<a name="line776"></a>               corner.TOP_RIGHT,
<a name="line777"></a>               f(corner.BOTTOM_RIGHT));
<a name="line778"></a>
<a name="line779"></a>  assertEquals(&#39;TOP_START should be flipped to BOTTOM_START.&#39;,
<a name="line780"></a>               corner.BOTTOM_START,
<a name="line781"></a>               f(corner.TOP_START));
<a name="line782"></a>  assertEquals(&#39;TOP_END should be flipped to BOTTOM_END.&#39;,
<a name="line783"></a>               corner.BOTTOM_END,
<a name="line784"></a>               f(corner.TOP_END));
<a name="line785"></a>  assertEquals(&#39;BOTTOM_START should be flipped to TOP_START.&#39;,
<a name="line786"></a>               corner.TOP_START,
<a name="line787"></a>               f(corner.BOTTOM_START));
<a name="line788"></a>  assertEquals(&#39;BOTTOM_END should be flipped to TOP_END.&#39;,
<a name="line789"></a>               corner.TOP_END,
<a name="line790"></a>               f(corner.BOTTOM_END));
<a name="line791"></a>}
<a name="line792"></a>
<a name="line793"></a>
<a name="line794"></a>function testFlipCorner() {
<a name="line795"></a>  var f = goog.positioning.flipCorner;
<a name="line796"></a>
<a name="line797"></a>  assertEquals(&#39;TOP_LEFT should be flipped to BOTTOM_RIGHT.&#39;,
<a name="line798"></a>               corner.BOTTOM_RIGHT,
<a name="line799"></a>               f(corner.TOP_LEFT));
<a name="line800"></a>  assertEquals(&#39;TOP_RIGHT should be flipped to BOTTOM_LEFT.&#39;,
<a name="line801"></a>               corner.BOTTOM_LEFT,
<a name="line802"></a>               f(corner.TOP_RIGHT));
<a name="line803"></a>  assertEquals(&#39;BOTTOM_LEFT should be flipped to TOP_RIGHT.&#39;,
<a name="line804"></a>               corner.TOP_RIGHT,
<a name="line805"></a>               f(corner.BOTTOM_LEFT));
<a name="line806"></a>  assertEquals(&#39;BOTTOM_RIGHT should be flipped to TOP_LEFT.&#39;,
<a name="line807"></a>               corner.TOP_LEFT,
<a name="line808"></a>               f(corner.BOTTOM_RIGHT));
<a name="line809"></a>
<a name="line810"></a>  assertEquals(&#39;TOP_START should be flipped to BOTTOM_END.&#39;,
<a name="line811"></a>               corner.BOTTOM_END,
<a name="line812"></a>               f(corner.TOP_START));
<a name="line813"></a>  assertEquals(&#39;TOP_END should be flipped to BOTTOM_START.&#39;,
<a name="line814"></a>               corner.BOTTOM_START,
<a name="line815"></a>               f(corner.TOP_END));
<a name="line816"></a>  assertEquals(&#39;BOTTOM_START should be flipped to TOP_END.&#39;,
<a name="line817"></a>               corner.TOP_END,
<a name="line818"></a>               f(corner.BOTTOM_START));
<a name="line819"></a>  assertEquals(&#39;BOTTOM_END should be flipped to TOP_START.&#39;,
<a name="line820"></a>               corner.TOP_START,
<a name="line821"></a>               f(corner.BOTTOM_END));
<a name="line822"></a>}
<a name="line823"></a>
<a name="line824"></a>function testPositionAtAnchorFrameViewportStandard() {
<a name="line825"></a>  var iframe = document.getElementById(&#39;iframe-standard&#39;);
<a name="line826"></a>  var iframeDoc = goog.dom.getFrameContentDocument(iframe);
<a name="line827"></a>  assertTrue(new goog.dom.DomHelper(iframeDoc).isCss1CompatMode());
<a name="line828"></a>
<a name="line829"></a>  new goog.dom.DomHelper(iframeDoc).getDocumentScrollElement().scrollTop = 100;
<a name="line830"></a>  var anchor = iframeDoc.getElementById(&#39;anchor1&#39;);
<a name="line831"></a>  var popup = document.getElementById(&#39;popup6&#39;);
<a name="line832"></a>
<a name="line833"></a>  var status = goog.positioning.positionAtAnchor(
<a name="line834"></a>      anchor, corner.TOP_RIGHT, popup, corner.BOTTOM_RIGHT);
<a name="line835"></a>  var iframeRect = goog.style.getBounds(iframe);
<a name="line836"></a>  var popupRect = goog.style.getBounds(popup);
<a name="line837"></a>  assertEquals(&#39;Status should not have any ADJUSTED and FAILED.&#39;,
<a name="line838"></a>               goog.positioning.OverflowStatus.NONE, status);
<a name="line839"></a>  assertRoundedEquals(&#39;Popup should be positioned just above the iframe, &#39; +
<a name="line840"></a>                      &#39;not above the anchor element inside the iframe&#39;,
<a name="line841"></a>                      iframeRect.top,
<a name="line842"></a>                      popupRect.top + popupRect.height);
<a name="line843"></a>}
<a name="line844"></a>
<a name="line845"></a>function testPositionAtAnchorFrameViewportQuirk() {
<a name="line846"></a>  var iframe = document.getElementById(&#39;iframe-quirk&#39;);
<a name="line847"></a>  var iframeDoc = goog.dom.getFrameContentDocument(iframe);
<a name="line848"></a>  assertFalse(new goog.dom.DomHelper(iframeDoc).isCss1CompatMode());
<a name="line849"></a>
<a name="line850"></a>  window.scrollTo(0, 100);
<a name="line851"></a>  new goog.dom.DomHelper(iframeDoc).getDocumentScrollElement().scrollTop = 100;
<a name="line852"></a>  var anchor = iframeDoc.getElementById(&#39;anchor1&#39;);
<a name="line853"></a>  var popup = document.getElementById(&#39;popup6&#39;);
<a name="line854"></a>
<a name="line855"></a>  var status = goog.positioning.positionAtAnchor(
<a name="line856"></a>      anchor, corner.TOP_RIGHT, popup, corner.BOTTOM_RIGHT);
<a name="line857"></a>  var iframeRect = goog.style.getBounds(iframe);
<a name="line858"></a>  var popupRect = goog.style.getBounds(popup);
<a name="line859"></a>  assertEquals(&#39;Status should not have any ADJUSTED and FAILED.&#39;,
<a name="line860"></a>               goog.positioning.OverflowStatus.NONE, status);
<a name="line861"></a>  assertRoundedEquals(&#39;Popup should be positioned just above the iframe, &#39; +
<a name="line862"></a>                      &#39;not above the anchor element inside the iframe&#39;,
<a name="line863"></a>                      iframeRect.top,
<a name="line864"></a>                      popupRect.top + popupRect.height);
<a name="line865"></a>}
<a name="line866"></a>
<a name="line867"></a>function testPositionAtAnchorFrameViewportWithPopupInScroller() {
<a name="line868"></a>  var iframe = document.getElementById(&#39;iframe-standard&#39;);
<a name="line869"></a>  var iframeDoc = goog.dom.getFrameContentDocument(iframe);
<a name="line870"></a>
<a name="line871"></a>  new goog.dom.DomHelper(iframeDoc).getDocumentScrollElement().scrollTop = 100;
<a name="line872"></a>  var anchor = iframeDoc.getElementById(&#39;anchor1&#39;);
<a name="line873"></a>  var popup = document.getElementById(&#39;popup7&#39;);
<a name="line874"></a>  popup.offsetParent.scrollTop = 50;
<a name="line875"></a>
<a name="line876"></a>  var status = goog.positioning.positionAtAnchor(
<a name="line877"></a>      anchor, corner.TOP_RIGHT, popup, corner.BOTTOM_RIGHT);
<a name="line878"></a>  var iframeRect = goog.style.getBounds(iframe);
<a name="line879"></a>  var popupRect = goog.style.getBounds(popup);
<a name="line880"></a>  assertEquals(&#39;Status should not have any ADJUSTED and FAILED.&#39;,
<a name="line881"></a>               goog.positioning.OverflowStatus.NONE, status);
<a name="line882"></a>  assertRoughlyEquals(&#39;Popup should be positioned just above the iframe, &#39; +
<a name="line883"></a>      &#39;not above the anchor element inside the iframe&#39;,
<a name="line884"></a>      iframeRect.top,
<a name="line885"></a>      popupRect.top + popupRect.height,
<a name="line886"></a>      ALLOWED_OFFSET);
<a name="line887"></a>}
<a name="line888"></a>
<a name="line889"></a>function testPositionAtAnchorNestedFrames() {
<a name="line890"></a>  var outerIframe = document.getElementById(&#39;nested-outer&#39;);
<a name="line891"></a>  var outerDoc = goog.dom.getFrameContentDocument(outerIframe);
<a name="line892"></a>  var popup = outerDoc.getElementById(&#39;popup1&#39;);
<a name="line893"></a>  var innerIframe = outerDoc.getElementById(&#39;inner-frame&#39;);
<a name="line894"></a>  var innerDoc = goog.dom.getFrameContentDocument(innerIframe);
<a name="line895"></a>  var anchor = innerDoc.getElementById(&#39;anchor1&#39;);
<a name="line896"></a>
<a name="line897"></a>  var status = goog.positioning.positionAtAnchor(
<a name="line898"></a>      anchor, corner.TOP_LEFT, popup, corner.BOTTOM_LEFT);
<a name="line899"></a>  assertEquals(&#39;Status should not have any ADJUSTED and FAILED.&#39;,
<a name="line900"></a>               goog.positioning.OverflowStatus.NONE, status);
<a name="line901"></a>  var innerIframeRect = goog.style.getBounds(innerIframe);
<a name="line902"></a>  var popupRect = goog.style.getBounds(popup);
<a name="line903"></a>  assertRoundedEquals(&#39;Top of frame should align with bottom of the popup&#39;,
<a name="line904"></a>                      innerIframeRect.top, popupRect.top + popupRect.height);
<a name="line905"></a>
<a name="line906"></a>  // The anchor is scrolled up by 10px.
<a name="line907"></a>  // Popup position should be the same as above.
<a name="line908"></a>  goog.dom.getWindow(innerDoc).scrollTo(0, 10);
<a name="line909"></a>  status = goog.positioning.positionAtAnchor(
<a name="line910"></a>      anchor, corner.TOP_LEFT, popup, corner.BOTTOM_LEFT);
<a name="line911"></a>  assertEquals(&#39;Status should not have any ADJUSTED and FAILED.&#39;,
<a name="line912"></a>               goog.positioning.OverflowStatus.NONE, status);
<a name="line913"></a>  innerIframeRect = goog.style.getBounds(innerIframe);
<a name="line914"></a>  popupRect = goog.style.getBounds(popup);
<a name="line915"></a>  assertRoundedEquals(&#39;Top of frame should align with bottom of the popup&#39;,
<a name="line916"></a>                      innerIframeRect.top, popupRect.top + popupRect.height);
<a name="line917"></a>}
<a name="line918"></a>
<a name="line919"></a>function testPositionAtAnchorOffscreen() {
<a name="line920"></a>  var offset = 0;
<a name="line921"></a>  var anchor = goog.dom.getElement(&#39;offscreen-anchor&#39;);
<a name="line922"></a>  var popup = goog.dom.getElement(&#39;popup3&#39;);
<a name="line923"></a>
<a name="line924"></a>  goog.positioning.positionAtAnchor(
<a name="line925"></a>      anchor, corner.TOP_LEFT, popup, corner.TOP_LEFT, null, null,
<a name="line926"></a>      overflow.ADJUST_X | overflow.ADJUST_Y);
<a name="line927"></a>  assertObjectEquals(
<a name="line928"></a>      newCoord(offset, offset), goog.style.getPageOffset(popup));
<a name="line929"></a>
<a name="line930"></a>  goog.positioning.positionAtAnchor(
<a name="line931"></a>      anchor, corner.TOP_LEFT, popup, corner.TOP_LEFT, null, null,
<a name="line932"></a>      overflow.ADJUST_X_EXCEPT_OFFSCREEN | overflow.ADJUST_Y);
<a name="line933"></a>  assertObjectEquals(
<a name="line934"></a>      newCoord(-1000, offset), goog.style.getPageOffset(popup));
<a name="line935"></a>
<a name="line936"></a>  goog.positioning.positionAtAnchor(
<a name="line937"></a>      anchor, corner.TOP_LEFT, popup, corner.TOP_LEFT, null, null,
<a name="line938"></a>      overflow.ADJUST_X | overflow.ADJUST_Y_EXCEPT_OFFSCREEN);
<a name="line939"></a>  assertObjectEquals(
<a name="line940"></a>      newCoord(offset, -1000), goog.style.getPageOffset(popup));
<a name="line941"></a>
<a name="line942"></a>  goog.positioning.positionAtAnchor(
<a name="line943"></a>      anchor, corner.TOP_LEFT, popup, corner.TOP_LEFT, null, null,
<a name="line944"></a>      overflow.ADJUST_X_EXCEPT_OFFSCREEN | overflow.ADJUST_Y_EXCEPT_OFFSCREEN);
<a name="line945"></a>  assertObjectEquals(
<a name="line946"></a>      newCoord(-1000, -1000),
<a name="line947"></a>      goog.style.getPageOffset(popup));
<a name="line948"></a>}
<a name="line949"></a>
<a name="line950"></a>function testPositionAtAnchorWithOverflowScrollOffsetParent() {
<a name="line951"></a>  var testAreaOffset = goog.style.getPageOffset(testArea);
<a name="line952"></a>  var scrollbarWidth = goog.style.getScrollbarWidth();
<a name="line953"></a>  window.scrollTo(testAreaOffset.x, testAreaOffset.y);
<a name="line954"></a>
<a name="line955"></a>  var overflowDiv = goog.dom.createElement(&#39;div&#39;);
<a name="line956"></a>  overflowDiv.style.overflow = &#39;scroll&#39;;
<a name="line957"></a>  overflowDiv.style.position = &#39;relative&#39;;
<a name="line958"></a>  goog.style.setSize(overflowDiv, 200 /* width */, 100 /* height */);
<a name="line959"></a>
<a name="line960"></a>  var anchor = goog.dom.createElement(&#39;div&#39;);
<a name="line961"></a>  anchor.style.position = &#39;absolute&#39;;
<a name="line962"></a>  goog.style.setSize(anchor, 50 /* width */, 50 /* height */);
<a name="line963"></a>  goog.style.setPosition(anchor, 300 /* left */, 300 /* top */);
<a name="line964"></a>
<a name="line965"></a>  var popup = createPopupDiv(75 /* width */, 50 /* height */);
<a name="line966"></a>
<a name="line967"></a>  goog.dom.append(testArea, overflowDiv, anchor);
<a name="line968"></a>  goog.dom.append(overflowDiv, popup);
<a name="line969"></a>
<a name="line970"></a>  // Popup should always be positioned within the overflowDiv
<a name="line971"></a>  goog.style.setPosition(overflowDiv, 0 /* left */, 0 /* top */);
<a name="line972"></a>  goog.positioning.positionAtAnchor(
<a name="line973"></a>      anchor, corner.TOP_LEFT, popup, corner.TOP_RIGHT, null, null,
<a name="line974"></a>      overflow.ADJUST_X | overflow.ADJUST_Y);
<a name="line975"></a>  assertObjectEquals(
<a name="line976"></a>      new goog.math.Coordinate(
<a name="line977"></a>          testAreaOffset.x + 200 - 75 - scrollbarWidth,
<a name="line978"></a>          testAreaOffset.y + 100 - 50 - scrollbarWidth),
<a name="line979"></a>      goog.style.getPageOffset(popup));
<a name="line980"></a>
<a name="line981"></a>  goog.style.setPosition(overflowDiv, 400 /* left */, 0 /* top */);
<a name="line982"></a>  goog.positioning.positionAtAnchor(
<a name="line983"></a>      anchor, corner.TOP_RIGHT, popup, corner.TOP_LEFT, null, null,
<a name="line984"></a>      overflow.ADJUST_X | overflow.ADJUST_Y);
<a name="line985"></a>  assertObjectEquals(
<a name="line986"></a>      new goog.math.Coordinate(
<a name="line987"></a>          testAreaOffset.x + 400, testAreaOffset.y + 100 - 50 - scrollbarWidth),
<a name="line988"></a>      goog.style.getPageOffset(popup));
<a name="line989"></a>
<a name="line990"></a>  goog.style.setPosition(overflowDiv, 0 /* left */, 400 /* top */);
<a name="line991"></a>  goog.positioning.positionAtAnchor(
<a name="line992"></a>      anchor, corner.BOTTOM_LEFT, popup, corner.BOTTOM_RIGHT, null, null,
<a name="line993"></a>      overflow.ADJUST_X | overflow.ADJUST_Y);
<a name="line994"></a>  assertObjectEquals(
<a name="line995"></a>      new goog.math.Coordinate(
<a name="line996"></a>          testAreaOffset.x + 200 - 75 - scrollbarWidth, testAreaOffset.y + 400),
<a name="line997"></a>      goog.style.getPageOffset(popup));
<a name="line998"></a>
<a name="line999"></a>  goog.style.setPosition(overflowDiv, 400 /* left */, 400 /* top */);
<a name="line1000"></a>  goog.positioning.positionAtAnchor(
<a name="line1001"></a>      anchor, corner.BOTTOM_RIGHT, popup, corner.BOTTOM_LEFT, null, null,
<a name="line1002"></a>      overflow.ADJUST_X | overflow.ADJUST_Y);
<a name="line1003"></a>  assertObjectEquals(
<a name="line1004"></a>      new goog.math.Coordinate(
<a name="line1005"></a>          testAreaOffset.x + 400, testAreaOffset.y + 400),
<a name="line1006"></a>      goog.style.getPageOffset(popup));
<a name="line1007"></a>
<a name="line1008"></a>  // No overflow.
<a name="line1009"></a>  goog.style.setPosition(overflowDiv, 300 - 50 /* left */, 300 /* top */);
<a name="line1010"></a>  goog.positioning.positionAtAnchor(
<a name="line1011"></a>      anchor, corner.TOP_LEFT, popup, corner.TOP_RIGHT, null, null,
<a name="line1012"></a>      overflow.ADJUST_X | overflow.ADJUST_Y);
<a name="line1013"></a>  assertObjectEquals(
<a name="line1014"></a>      new goog.math.Coordinate(
<a name="line1015"></a>          testAreaOffset.x + 300 - 50, testAreaOffset.y + 300),
<a name="line1016"></a>      goog.style.getPageOffset(popup));
<a name="line1017"></a>}
<a name="line1018"></a>
<a name="line1019"></a>function testPositionAtAnchorWithOverflowHiddenParent() {
<a name="line1020"></a>  var testAreaOffset = goog.style.getPageOffset(testArea);
<a name="line1021"></a>  window.scrollTo(testAreaOffset.x, testAreaOffset.y);
<a name="line1022"></a>
<a name="line1023"></a>  var overflowDiv = goog.dom.createElement(&#39;div&#39;);
<a name="line1024"></a>  overflowDiv.style.overflow = &#39;hidden&#39;;
<a name="line1025"></a>  overflowDiv.style.position = &#39;relative&#39;;
<a name="line1026"></a>  goog.style.setSize(overflowDiv, 200 /* width */, 100 /* height */);
<a name="line1027"></a>
<a name="line1028"></a>  var anchor = goog.dom.createElement(&#39;div&#39;);
<a name="line1029"></a>  anchor.style.position = &#39;absolute&#39;;
<a name="line1030"></a>  goog.style.setSize(anchor, 50 /* width */, 50 /* height */);
<a name="line1031"></a>  goog.style.setPosition(anchor, 300 /* left */, 300 /* top */);
<a name="line1032"></a>
<a name="line1033"></a>  var popup = createPopupDiv(75 /* width */, 50 /* height */);
<a name="line1034"></a>
<a name="line1035"></a>  goog.dom.append(testArea, overflowDiv, anchor);
<a name="line1036"></a>  goog.dom.append(overflowDiv, popup);
<a name="line1037"></a>
<a name="line1038"></a>  // Popup should always be positioned within the overflowDiv
<a name="line1039"></a>  goog.style.setPosition(overflowDiv, 0 /* left */, 0 /* top */);
<a name="line1040"></a>  goog.positioning.positionAtAnchor(
<a name="line1041"></a>      anchor, corner.TOP_LEFT, popup, corner.TOP_RIGHT, null, null,
<a name="line1042"></a>      overflow.ADJUST_X | overflow.ADJUST_Y);
<a name="line1043"></a>  assertObjectEquals(
<a name="line1044"></a>      new goog.math.Coordinate(
<a name="line1045"></a>          testAreaOffset.x + 200 - 75, testAreaOffset.y + 100 - 50),
<a name="line1046"></a>      goog.style.getPageOffset(popup));
<a name="line1047"></a>
<a name="line1048"></a>  goog.style.setPosition(overflowDiv, 400 /* left */, 0 /* top */);
<a name="line1049"></a>  goog.positioning.positionAtAnchor(
<a name="line1050"></a>      anchor, corner.TOP_RIGHT, popup, corner.TOP_LEFT, null, null,
<a name="line1051"></a>      overflow.ADJUST_X | overflow.ADJUST_Y);
<a name="line1052"></a>  assertObjectEquals(
<a name="line1053"></a>      new goog.math.Coordinate(
<a name="line1054"></a>          testAreaOffset.x + 400, testAreaOffset.y + 100 - 50),
<a name="line1055"></a>      goog.style.getPageOffset(popup));
<a name="line1056"></a>
<a name="line1057"></a>  goog.style.setPosition(overflowDiv, 0 /* left */, 400 /* top */);
<a name="line1058"></a>  goog.positioning.positionAtAnchor(
<a name="line1059"></a>      anchor, corner.BOTTOM_LEFT, popup, corner.BOTTOM_RIGHT, null, null,
<a name="line1060"></a>      overflow.ADJUST_X | overflow.ADJUST_Y);
<a name="line1061"></a>  assertObjectEquals(
<a name="line1062"></a>      new goog.math.Coordinate(
<a name="line1063"></a>          testAreaOffset.x + 200 - 75, testAreaOffset.y + 400),
<a name="line1064"></a>      goog.style.getPageOffset(popup));
<a name="line1065"></a>
<a name="line1066"></a>  goog.style.setPosition(overflowDiv, 400 /* left */, 400 /* top */);
<a name="line1067"></a>  goog.positioning.positionAtAnchor(
<a name="line1068"></a>      anchor, corner.BOTTOM_RIGHT, popup, corner.BOTTOM_LEFT, null, null,
<a name="line1069"></a>      overflow.ADJUST_X | overflow.ADJUST_Y);
<a name="line1070"></a>  assertObjectEquals(
<a name="line1071"></a>      new goog.math.Coordinate(
<a name="line1072"></a>          testAreaOffset.x + 400, testAreaOffset.y + 400),
<a name="line1073"></a>      goog.style.getPageOffset(popup));
<a name="line1074"></a>
<a name="line1075"></a>  // No overflow.
<a name="line1076"></a>  goog.style.setPosition(overflowDiv, 300 - 50 /* left */, 300 /* top */);
<a name="line1077"></a>  goog.positioning.positionAtAnchor(
<a name="line1078"></a>      anchor, corner.TOP_LEFT, popup, corner.TOP_RIGHT, null, null,
<a name="line1079"></a>      overflow.ADJUST_X | overflow.ADJUST_Y);
<a name="line1080"></a>  assertObjectEquals(
<a name="line1081"></a>      new goog.math.Coordinate(
<a name="line1082"></a>          testAreaOffset.x + 300 - 50, testAreaOffset.y + 300),
<a name="line1083"></a>      goog.style.getPageOffset(popup));
<a name="line1084"></a>}
<a name="line1085"></a>
<a name="line1086"></a>function createPopupDiv(width, height) {
<a name="line1087"></a>  var popupDiv = goog.dom.createElement(&#39;div&#39;);
<a name="line1088"></a>  popupDiv.style.position = &#39;absolute&#39;;
<a name="line1089"></a>  goog.style.setSize(popupDiv, width, height);
<a name="line1090"></a>  goog.style.setPosition(popupDiv, 0 /* left */, 250 /* top */);
<a name="line1091"></a>  return popupDiv;
<a name="line1092"></a>}
<a name="line1093"></a>
<a name="line1094"></a>function newCoord(x, y) {
<a name="line1095"></a>  return new goog.math.Coordinate(x, y);
<a name="line1096"></a>}
<a name="line1097"></a>
<a name="line1098"></a>function newSize(w, h) {
<a name="line1099"></a>  return new goog.math.Size(w, h);
<a name="line1100"></a>}
</pre>


</body>
</html>
